package com.livestocksolutions.ui;

import com.livestocksolutions.R;
import com.livestocksolutions.intent.BaseActivity;

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

/* -- Version History --
 *  1.0 : 01 August 2012 - Initial version.
 *  
 *  1.1 : 17 September 2012 - Class now extends ViewChemicineArrayAdapter.
 */

/**
 * A base class to create the layout for the list of Chemicals or Medicines
 * @author Adam Parr
 * @version 1.1
 * 
 * @.modified 19 October 2012
 */
public class ListChemicineArrayAdapter extends ViewChemicineArrayAdapter {
	/**
	 * Size of the allowable array passed
	 */
	public static final int SIZE = 3;
	/**
	 * Unique ID for each position within the String[position][{@value #ID}] array passed in the Constructor.
	 */
	public static final int ID = 0;
	/**
	 * Name position within the String[position][{@value #NAME}] array passed in the Constructor.
	 */
	public static final int NAME = 1;
	/**
	 * Purchase Date position within the String[position][{@value #PURCHASEDATE}] array passed in the Constructor.
	 */
	public static final int PURCHASEDATE = 2;
 
	/**
	 * Constructor
	 * @param context The current context.
	 * @param values The Chemical/Medicines to represent in the ListView.
	 */
	public ListChemicineArrayAdapter(BaseActivity context, String[][] values) {
		super(context, values);
	}
	
	/**
	 * Set the TextView id to inflate when creating this list
	 * @param textViewResourceId the TextView id to inflate when {@link #getView(int, View, ViewGroup)} is called.
	 */
	@Override
	public void setView(int textViewResourceId){
		this.textViewResourceId=textViewResourceId;
	}
 
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View rowView = super.setView(position, convertView, parent);
		
		TextView chemicineName = (TextView) rowView.findViewById(R.id.chemicineName);
		TextView chemicinePurchaseDate = (TextView) rowView.findViewById(R.id.chemicinePurchaseDate);
		
		chemicineName.setText(values[position][NAME]);
		String s = context.format(context.parse(values[position][PURCHASEDATE]));
		chemicinePurchaseDate.setText(!s.equals("")?s:context.getResources().getString(R.string.message_noText,context.getResources().getString(R.string.message_notSet)));

		return rowView;
	}
}
